package com.manage.modules.domain;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.manage.common.core.domain.TreeSelect;
import com.manage.common.core.domain.entity.SysMenu;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 树结构实体
 *
 * @author xu
 * 2021/8/12 9:46
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
public class TreeSelectModel {
    private static final long serialVersionUID = 1L;

    /**
     * 节点ID
     */
    private Long id;

    /**
     * 节点名称
     */
    private String label;

    /**
     * 子节点
     */
    @JsonInclude(JsonInclude.Include.NON_EMPTY)
    private List<TreeSelectModel> children;


    public TreeSelectModel(TBaseArea baseArea) {
        this.id = baseArea.getAreaId();
        this.label = baseArea.getAreaName();
        this.children = baseArea.getChildren().stream().map(TreeSelectModel::new).collect(Collectors.toList());
    }

    public TreeSelectModel(TBaseStationType baseStationType) {
        this.id = baseStationType.getStationTypeId();
        this.label = baseStationType.getStationTypeName();
        this.children = baseStationType.getChildren().stream().map(TreeSelectModel::new).collect(Collectors.toList());
    }
}
